# @Time    :2025/3/28 17:24
#  匿名函数 ：  lambda 参数：表达式（函数体）

# 有三名学生的姓名和年龄，按年龄排序。
student_list = [{"name": "zhang3", "age": 36},
                {"name": "li4", "age": 14},
                {"name": "wang5", "age": 27}]

student_list.sort(key= lambda stu: stu["age"])
print(student_list)
"""
对字典的操作

"""
#print(sorted(student_list, key=lambda x: x["age"]))




# # 有三名学生的姓名和年龄，按年龄排序。
# student_list = [{"name": "zhang3", "age": 36},
#                 {"name": "li4", "age": 14},
#                 {"name": "wang5", "age": 27}]
#
# def getKey(std):
#     return std["age"]
# student_list.sort(key= getKey)
# #student_list.sort(key= lambda stu: stu["age"])
#
# print(student_list)












"""# 有三名学生的姓名和年龄，按年龄排序。
student_list = [{"name": "zhang3", "age": 36},
                {"name": "li4", "age": 14},
                {"name": "wang5", "age": 27}]

# def getKey(std):
#     return std["age"]
# student_list.sort(key= getKey)
student_list.sort(key= lambda stu: stu["age"])
print(student_list)
"""


#---------------------
# for i in student_list

"""# for i in student_list:
#     # def getKey(std):
#     #     return std["age"]
#     # student_list.sort(key= getKey)
#     student_list.sort(key=lambda stu: stu["age"])
#     print(student_list)

#    student_list.sort("age")


# #reversed=True
# list1 = [1, 3, 5, 7, 8]
# list1.sort()
# print(list1)
"""